package xmltomce;
import java.io.File;

import org.w3c.dom.Element;


/**
 * @author  Lord eAgle
 */
public class InfoCacheXmlWriter extends XmlWriter{
	private File infoCacheFolder;
	private Movie movie;
	
	public InfoCacheXmlWriter(File infoCacheFolder){
		if (infoCacheFolder.isDirectory()){
			this.infoCacheFolder = infoCacheFolder;
		}
	}
	
	public void saveXmlFile(Movie movie){
		String xmlFilePath = infoCacheFolder.getAbsolutePath()+"\\"+movie.getXmlId();
		this.movie = movie;
		createDocument();
		createXmlStructure();
		printToFile(xmlFilePath);
	}
	
	protected void createXmlStructure(){
		Element root = dom.createElement("METADATA");
		root.setAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
		root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
		dom.appendChild(root);
		
		Element dvd = dom.createElement("MDR-DVD");
		root.appendChild(dvd);
		
		appendTextChild(dvd, "dvdTitle", movie.getTitle());
		appendTextChild(dvd, "director", movie.getDirector());
		appendTextChild(dvd, "leadPerformer", movie.getActors());
		appendTextChild(dvd, "releaseDate", movie.getReleaseDate());
		appendTextChild(dvd, "genre", movie.getGenre());
		appendTextChild(dvd, "largeCoverParams", movie.getLargeCoverPath());
		appendTextChild(dvd, "smallCoverParams", movie.getSmallCoverPath());
		appendTextChild(dvd, "duration", ""+movie.getRuntimeInMinutes());
		
		Element title = dom.createElement("title");
		dvd.appendChild(title);
		appendTextChild(title, "synopsis", movie.getPlot());
		
		appendTextChild(root, "DvdId", ""+movie.getXmlId());
		
	}

}
